import request from '@/api/axios'
import {AxiosPromise} from 'axios'
import {DataRes, Paging} from '@/api/config'

// 列表数据
export interface SearchData extends Paging{
  instrumentName:string, // 仪器名称
  companyId:number|string, // 生产厂家id
  model:string, // 仪器型号
  instrumentType:number // 仪器分类编码
  instrumentClass:string//检验仪器类型
}

// 列表数据
export interface SearchData1{
  instrumentName:string, // 仪器名称
  companyId:number|string, // 生产厂家id
  model:string, // 仪器型号
  instrumentClass:string//仪器分类
  instrumentType:number // 仪器分类编码
}

// 列表数据
export interface TableData{
  instrumentName:string, // 仪器名称
  instrumentCode:string, // 仪器编码
  companyName:string, // 仪器生产厂家
  model:string, //	仪器型号
  reagentNames:string, //关联试剂
  instrumentTypeName:string
  instrumentClass:string
  operation?:any
}

// 下来数据
export interface ClassData{
  dictItemCode?:string,
  dictItemName?:string,
  value?:string|number,
  label?:string|number
}

// 关联试剂数据
export interface ReagentData{
  id:string,
  consumableProductName:string,
  value?:string|number,
  label?:string|number
}
// 关联生产厂家数据
export interface mechanismData{
  orgCode:string,
  orgGradeName:string,
  orgName:string,
  id:string,
  value?:string|number,
  label?:string|number
}
// 关联生产厂家数据
export interface SaveData{
  instrumentId?:string,
  instrumentName?:string, // 仪器名称
  instrumentType?:number, // 仪器分类编码
  instrumentClass?:string, //检验仪器类型
  reagents?:Array<string>, // 选择的试剂数组
  companyId?:string, // 生产厂家id
  specimenRule:string//标本号规则
  maxSpecimen?:string//最大标本号
  id?:string,
  brandType?:string, // 品牌类型编码:进口/合资等
  model?:string,
  communicationType?:number,
  networkInterface?:string,
  serverPort?:string,
  serverIp?:string,
  serialPortName?:string,
  baudRate?:string,
  checkBit?:string,
  dataBit?:string,
  stopBit?:string,
  databaseType?:string,
  databaseAddress?:string,
  username?:string,
  password?:string,
  coding?:string,
  readFrequency?:string,
  filePath?:string,
}
// 维护子项搜索数据
export interface ItemLists{
  instrumentId:string,
  inspectItemName?:string, // 仪器名称
  inspectItemType?:string, // 仪器分类编码
  inspectFunctionCode?:string // 选择的试剂数组
  inspectItemCode?:string
  inspectMethod?:string
  keywords?:string
}

// 维护子项搜索数据
export interface ItemList extends Paging{
  instrumentId:string,
  inspectItemName?:string, // 仪器名称
  inspectItemType?:string, // 仪器分类编码
  inspectFunctionCode?:string // 选择的试剂数组
  inspectItemCode?:string
  inspectMethod?:string
}

// 维护子项列表数据
export interface ItemData{
  id:string,
  inspectItemCode:string, // 仪器名称
  inspectItemName:string, // 仪器分类编码
  englishName:string, // 选择的试剂数组
  inspectItemType:string,
  inspectFunctionCode:string,
  inspectItemId?:string,
  calOptions?:string,
  operation?:any
}

// 仪器生产厂家下拉数据数据
export interface SearchableData{
  orgId:string, // 仪器名称
  orgName:string, // 仪器分类编码
  value?:string|number,
  label?:string|number
}
// 仪器生产厂家下拉数据数据
export interface InspectItemListAdd{
  id:string,
  inspectItemCode:string, // 检验子项编码
  inspectItemName:string, // 检验子项名称
  operation?:any
}

// 为仪器维护检验子项
export interface SetInspectItemData{
  instrumentId:string,
  inspects:Array<string> // 检验子项编码
}

// 为仪器维护检验子项
export interface ExceptIdsData{
  exceptIds:any,
  inspectItemType?:string,
  keywords:string
}

// 查询仪器检验子项的参考范围
export interface ReferenceRangeData{
  instrumentId:string,
  inspectItemId:string,
  reagentId:string|null
}


export interface itemInforList {
  size:number
  total:number
  records:Array<TableData>
}

//检验仪器设备列表数据  改
export const instrumentpage = (params:SearchData):AxiosPromise<DataRes<itemInforList>> => {
  return request({
    url:'/api/instrument/page',
    method:'get',
    params
  })
}



//新增或修改仪器知识库信息
export const instrumentSave = (data:SaveData):AxiosPromise<DataRes<undefined>> => {
  return request({
    url:'/api/instrument/save',
    method:'post',
    data
  })
}
// 维护检查项目列表数据
export interface TableDataList{
  id?:string //id
  itemName?:string, // 仪器名称
  itemCode?:string, // 仪器编码
  enShortName?:string, // 英文名称
  operation?:any
}
// 维护检查项目搜索
export interface searchDataList{
  itemName?:string, // 仪器名称
  itemCode?:string, // 仪器编码
  page?:number, // 默认页码
  limit?:number, // 默认每页条数
  instrumentId?:string, // 仪器id
}

export interface itemInspectItemList {
  size:number
  total:number
  records:Array<any>
}
//查询仪器的检验子项  维护检查设备分页
export const inspectItemList = (params:searchDataList):AxiosPromise<DataRes<itemInspectItemList>> => {
  return request({
    url:'/api/instrument/item/page',
    method:'get',
    params
  })
}
//查询仪器的检验子项  维护参考区间列表
export const inspectItemListCanKao = (params:ItemLists):AxiosPromise<DataRes<itemInspectItemList>> => {
  return request({
    url:'/api/instrument/inspectItem/list',
    method:'get',
    params
  })
}

export interface AllByOrgId extends Paging{
  orgId:string
  name?:string|null
}

//删除
export const instrumentDelete = (data:{id:string}):AxiosPromise<DataRes<Array<SearchableData>>> => {
  return request({
    url:'/api/instrument/remove/' + data.id,
    method:'post'
  })
}

// 为仪器维护检验子项
export interface ExceptIdsDataNew{
  instrumentId:string,
  checkType:string,
}
//根据条件查询所有子项  改
export const inspectItemListAdd = (params:ExceptIdsDataNew):AxiosPromise<DataRes<Array<InspectItemListAdd>>> => {
  // console.log(params, '---params----')
  return request({
    url:'/api/item/list',
    method:'get',
    params
  })
}



//为仪器维护检验子项保存
export const inspectItemSave = (data:SetInspectItemData):AxiosPromise<DataRes<Array<InspectItemListAdd>>> => {
  return request({
    url:'/api/instrument/inspectItem/save',
    method:'post',
    data
  })
}

// 查询仪器检验子项的参考范围
export interface ReferenceRangeDataList{
  instrumentId:string,
  itemId:string
}


//根据仪器id与检验子项id删除它们的关系
// instrumentId	仪器 idinspectItemId	检验子项id
export const inspectItemDelete = (data:{instrumentId:string, inspectItemId:string}):AxiosPromise<DataRes<Array<InspectItemListAdd>>> => {
  return request({
    url:'/api/instrument/inspectItem/remove/' + data.instrumentId + '/' + data.inspectItemId,
    method:'post',
    data
  })
}


// 获取子页面数据8.25
export const getAllData = (instrumentId:string):AxiosPromise<DataRes<SaveData>> => {
  return request({
    url:`/api/instrument/detail/${instrumentId}`,
    method:'get'
  })
}



export interface SaveComunite{
  instrumentId?:string,
  labInstrumentId?:string, // 仪器部署id
  id?:string,
  communicationType?:string,
  networkInterface?:string,
  serverPort?:string,
  serverIp?:string,
  serialPortName?:string,
  baudRate?:string,
  checkBit?:string,
  dataBit?:string,
  stopBit?:string,
  databaseType?:string,
  databaseAddress?:string,
  username?:string,
  password?:string,
  coding?:string,
  readFrequency?:string,
  filePath?:string,
}


// 维护检查项目新增页面ts类型
export interface InspectItemListAddNew{
  id?:string,
  itemCode?:string, // 检验子项编码
  itemName?:string, // 检验子项名称
  operation?:any
}
//w维护检查项目的新增弹窗-左边搜索项定义
export interface SearchReportFromDataLeft{
  value?:string|null,
}
//w维护检查项目的新增弹窗-右边边搜索项定义
export interface SearchReportFromDataRight{
  keywords?:string|null,
  inspectItemType?:string|null
}